const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 联系人
    contact: {
      username: '老胡',
      phone: '13800000000',
      address: '广东省深圳市龙岗区龙岗街道12345号',
    },
    address: '',
    goodsLength: 0,
    orderInfo: { "totalMoney": 0, "goodsList": [{ "_id": "5cf668b48d64fb4df433364c", "productId": "5cf65d1f44f87c016cf3d034", "buyNum": 2, "masterName": "王小波杂文套装", "price": 12480, "imgUrl": "https://mall.s.maizuo.com/1a2eb3f79cf82b1ebccfcebe40b3365a.png", "slaveName": "自由理性、特立独行、黑色幽默，王小波经典四本杂文书信", "created": 1559652532748 }, { "_id": "5cf6697c8d64fb4df433364d", "productId": "5cf65d1f44f87c016cf3d037", "buyNum": 2, "masterName": "张爱玲全集02：红玫瑰与白玫瑰（2019版）", "price": 4290, "imgUrl": "https://mall.s.maizuo.com/d4d0ef5b515c0ae0729303d57132c9af.png", "slaveName": "全新精装，臻美典藏，月亮构筑起的永恒传奇", "created": 1559652732293 }, { "_id": "5cf8ca995392683f6c047e37", "productId": "5cf65d1f44f87c016cf3d034", "buyNum": 1, "masterName": "王小波杂文套装", "price": 12480, "imgUrl": "https://mall.s.maizuo.com/1a2eb3f79cf82b1ebccfcebe40b3365a.png", "slaveName": "自由理性、特立独行、黑色幽默，王小波经典四本杂文书信", "created": 1559808665712 }] }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // let orderInfo = JSON.parse(options.orderInfo);
    // let goodsLength = 0;
    // // 计算商品的总数量
    // orderInfo.goodsList.forEach(item => {
    //   goodsLength += item.buyNum;
    // })
    // this.setData({
    //   goodsLength,
    //   orderInfo
    // })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  onSubmit() {
    let url = '/order/add';
    let data = {
      contact: this.data.contact,
      totalMoney: this.data.orderInfo.totalMoney,
      goodsList: this.data.orderInfo.goodsList
    }
    app.$http.post(url,data).then(res=> {
      console.log(res);
      wx.navigateTo({
        url: '/pages/orderDetail/index',
      })
    });
  }
})